function csv2array_replace(csv){
	var arrstr = csv.replace(/,?\r?\n/g,'"],["').replace(/\s*,\s*/g,'","').replace(/^/,'[["').replace(/","\["$/,']').replace(/\]","\[/g,'],[');
	return eval(arrstr);
}

function csv2array(csv){
	var oarray = new Array();
	var arrstr = csv.split(/\r?\n/);
	var j=0;
	for(var i=0;i<arrstr.length;i++){
		var arr = arrstr[i].replace(/,\s*$/,'').split(/"?\s*,\s*"?/);
		oarray[j++]=arr;
	}
	return oarray;
}
function prepareForFlot(arr, map, start, maxminfield, labelfield, labelstep, labelstart){
	if(!start){
		start = 0;
	}
	var maxval=NaN;
	var minval=NaN;
	var oarray = new Array();
	var xarray = new Array();
	var j=start;
	for(var i = start ;i<arr.length;i++){
		var oobj = [i];
		var hasval = false;
		for (key in map){
			var k=1;
			var val = arr[i][map[key]];
			if((j % labelstep)==labelstart){
				xarray.push([j,(arr[i][labelfield]).replace(/([0-9]{4})([0-9]{2})([0-9]{2})/,'$1/$2/$3')]);
			}
			if(key == maxminfield && !isNaN(parseFloat(val))){
				val = parseFloat(val);
				if(isNaN(maxval)){
					maxval = val;
					minval = val;
				}else{
					maxval=Math.max(val,maxval);
					minval=Math.min(val,minval);
				}
				hasval = true;
			}
			oobj[k++] = val;
		}
		if(hasval){
			j++;
			oarray.push(oobj);
		}
	}
	oarray;
	return {"labels": xarray,"values": oarray, "maxval":maxval, "minval":minval};
}

function prepareForYUIDDataSource(arr, map, start, maxminfield){
	if(!start){
		start = 0;
	}
	var maxval=NaN;
	var minval=NaN;
	var oarray = new Array();
	var j=0;
	for(var i = start ;i<arr.length;i++){
		var oobj = {};
		for (key in map){
			var val = arr[i][map[key]];
			if(key == maxminfield && !isNaN(parseFloat(val))){
				if(isNaN(maxval)){
					maxval = val;
					minval = val;
				}else{
					maxval=Math.max(val,maxval);
					minval=Math.min(val,minval);
				}
			}
			oobj[key] = val;
		}
		oarray[j++] = oobj;
	}
	oarray;
	return {"properties": oarray, "maxval":maxval, "minval":minval};
}